#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<assert.h>
#include<stdlib.h>
#include<sys/wait.h>
int main()
{
	pid_t id=fork();
	assert(id!=-1);
	if(id==0){
		//child
		int cnt=5;
		while(cnt){
			printf("我是子进程,pid=%d  ppid=%d,cnt=%d\n",getpid(),getppid(),cnt--);
			sleep(1);
			//int* p=NULL;
			//*p=100;//野指针问题
		}
		exit(10);
	}
	//parent
	int status=0;
    int ret=waitpid(id,&status,0);
	if(ret>0){
		//printf("wait sucess,exit code:%d  signal:%d\n",(status>>8)&0xFF,status&0x7F);
		if(WIFEXITED(status)){
			printf("exit code:%d\n",WEXITSTATUS(status));
		}
	}
	return 0;
}
